<template>
    <div>
        <div style="margin: 10px 0; ">
            <el-input  placeholder="请输入学号" style="width: 400px;" suffix-icon="el-icon-search
    " v-model="studentId">
        </el-input ><el-button  class="ml-5" type="primary" @click="load" icon="el-icon-search">搜索</el-button>
        <el-button  class="ml-5" type="primary" @click="reset" icon="el-icon-refresh" >重置</el-button>
        <el-button  class="ml-5" type="primary" @click="show" icon="el-icon-position" >待审核查询</el-button>
        </div>
    
        <el-table :data="tableData"  stripe :header-cell-class-name="headerBg" border @selection-change="handleSelectionChange">
          <el-table-column
          type="selection"
          width="55">
        </el-table-column>
          <el-table-column prop="studentId" label="学号" width="200">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="200">
            </el-table-column>
            <el-table-column prop="scho" label="奖项" width="100">
            </el-table-column>
            <el-table-column prop="scholarshipS" label="奖金" width="150">
            </el-table-column>
            <el-table-column prop="score" label="加权成绩" width="150">
            </el-table-column>

          <el-table-column prop="status" label="申请状态">
            <template slot-scope="scope">
              <el-steps :space="100" :active="getActiveStep(scope.row.status)" :finish-status="getFinishStatus(scope.row.status)">
                <el-step title="提交申请"></el-step>
                <el-step title="审核中"></el-step>
                <el-step title="审核结果"></el-step>
              </el-steps>
            </template>
          </el-table-column>


              <el-table-column>
                <template slot-scope="scope">
                  <el-button type="primary" icon="el-icon-user" @click="handleEdit(scope.row.studentId)"></el-button>
                  <el-button type="primary" icon="el-icon-check" slot="reference" @click="handleAdd(scope.row.studentId)" ></el-button>
                  <el-popconfirm
                  confirm-button-text='确定'
                  cancel-button-text='取消'
                  icon="el-icon-info"
                  icon-color="red"
                  title="你确定驳回么"
                  @confirm="del(scope.row.studentId)"
                  >
                  <el-button type="danger" icon="el-icon-close" slot="reference"></el-button></el-popconfirm>
                  
                </template>
              </el-table-column>
        </el-table>
        <div class="block" style="padding: 10px;">
        
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
      <!-- 弹窗 -->
      <el-dialog title="学生信息" :visible.sync="scoringDetailsVisible" width="50%" top="200px">
      <div v-if="rule" style="font-size: 20px; line-height: 3;">
       <p>学号:{{ student.studentId }}&nbsp;&nbsp;&nbsp;姓名:{{ student.name }}</p>
       <p>年级:{{ student.grade }}</p>
       <p>专业:{{ student.department }}</p>
       <p>入学年份:{{ student.enrollmentYear }}</p>
       <p>联系方式:{{ student.contactInfo }}</p>
      
     
    </div>
    </el-dialog>
      
    </div>
    </template>
    
    
    <script>
    
    import request from '../../utils/request';
    
    
    
    export default{
        name: 'Suser',
        data(){
          
      return{
        tableData:[],
        total: 0,
        pageNum:1,
        pageSize: 5,
        studentId:'',
        status:'',
        headerBg:'headerBg',
        multipleSelection: [],
        bohui:{},
        student:{

        },
        rule:{

        },
        scoringDetailsVisible: false,
        form:{
          studentId: '',
          name: '',
          enrollmentYear: '',
          department: '',
          grade: '',
          contactInfo: '',
    
        }
      }
      },
      created(){
        this.load()
      },
      methods: {
      load(){
        request.get("/scholarship/all",{
          params:{
            pageNum : this.pageNum,
            pageSize: this.pageSize,
            studentId: this.studentId,
            status: this.status
          }
        }).then(res => {
          console.log(res)
          this.tableData = res.data.records
          this.total = res.data.total
        })
      },
      handleSizeChange(pageSize) {
        console.log(pageSize)
        this.pageSize = pageSize
        this.load()
       
      },
      handleCurrentChange(pageNum) {
        console.log(pageNum)
        this.pageNum = pageNum
       this.load()
      },
      show(){
        this.status = "待审核"
        this.load()
      },
      // 重置按钮
      reset(){
        this.studentId=''
        this.status=''
        this.load()
      },
      getActiveStep(status) {
        switch (status) {
          case '待审核':
            return 1;
          case '审核中':
            return 2;
          case '审核通过':
            
            return 3;
         case '未通过':
            return 3;
          default:
            return 1;
        }
      },
      getFinishStatus(status){
        switch (status) {
      case '待审核':
        return 'success';
      case '审核中':
        return 'success';
      case '审核通过':
        return 'success';
      case '未通过':
        return 'error';
      default:
        return 'wait'; 
      }},
    
     
      handleSelectionChange(val){
        this.multipleSelection = val
      },
      handleEdit(id){
        this.scoringDetailsVisible = true 
        request.get("/rules/getmsg?userId="+id).then(res =>{
            this.rule = res.data.rule
            this.student = res.data.student
        })
      },
      handleAdd(studentId){
        request.get("/scholarship/change",{
          params:{
            studentId:studentId,
          }
        }).then(res =>{
            if(res.data.code ===0){
              this.$message({
                message: res.data.msg,
                type: 'success'
           }),
           this.load()
            }else{
              this.$message.error({
            
               message: res.data.msg,
            
           })
           this.load()
            }
        })
      },
      del(studentId){
        this.bohui.studentId = studentId
        request.post("/scholarship/return",this.bohui).then(res => {
          if(res.data.code === 0){
              this.$message({
                message: res.data.msg,
                type: 'success'
           }),
           this.load()
            }else{
              this.$message.error({
            
               message: res.data.msg,
            
           })
           this.load()
            }
        })
      }

     }
    }
     
    </script>
    
    <style scoped>
    .headerBg{
      background-color: #bcb7b7!important;
    }
    </style>